package cn.edu.sdjzu.xg2106.util;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JSONUtil {
    //从参数的输入流读取数据，返回数据的JSON格式
    public static String getJSON(HttpServletRequest request) throws IOException {
        ServletInputStream requestStream = request.getInputStream();
        InputStreamReader requestStreamReader = new InputStreamReader(requestStream,"UTF-8");
        BufferedReader streamReader = new BufferedReader(requestStreamReader);
        StringBuilder parama_json = new StringBuilder();
        String line = null;
        while((line=streamReader.readLine())!=null){
            parama_json.append(line);
        }
        return parama_json.toString();
    }
}
